package com.enjoyor.soa.traffic.core.tsms.service.impl;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.core.tsms.domain.ExecuteTaskInfo;
import com.enjoyor.soa.traffic.core.tsms.domain.RltRouteDevice;
import com.enjoyor.soa.traffic.core.tsms.domain.RltRoutePost;
import com.enjoyor.soa.traffic.core.tsms.domain.RltTaskTime;
import com.enjoyor.soa.traffic.core.tsms.domain.RouteInfo;
import com.enjoyor.soa.traffic.core.tsms.domain.RoutePoint;
import com.enjoyor.soa.traffic.core.tsms.domain.SchemeCheck;
import com.enjoyor.soa.traffic.core.tsms.domain.SchemeFile;
import com.enjoyor.soa.traffic.core.tsms.domain.SchemeInfo;
import com.enjoyor.soa.traffic.core.tsms.domain.TaskDetailInfo;
import com.enjoyor.soa.traffic.core.tsms.domain.TaskInfo;
import com.enjoyor.soa.traffic.core.tsms.enums.EnumDicPublic;
import com.enjoyor.soa.traffic.core.tsms.mapper.IExecuteTaskInfoMapper;
import com.enjoyor.soa.traffic.core.tsms.mapper.IRltTaskTimeMapper;
import com.enjoyor.soa.traffic.core.tsms.mapper.IRouteInfoMapper;
import com.enjoyor.soa.traffic.core.tsms.mapper.ISchemeCheckMapper;
import com.enjoyor.soa.traffic.core.tsms.mapper.ISchemeFileMapper;
import com.enjoyor.soa.traffic.core.tsms.mapper.ISchemeInfoMapper;
import com.enjoyor.soa.traffic.core.tsms.mapper.ITaskDetailInfoMapper;
import com.enjoyor.soa.traffic.core.tsms.mapper.ITaskInfoMapper;
import com.enjoyor.soa.traffic.core.tsms.service.ISchemeInfoService;
import com.enjoyor.soa.traffic.frame.logger.IPubLogMapper;
import com.enjoyor.soa.traffic.util.enums.log.LogInfoDic;
import com.enjoyor.soa.traffic.util.helper.GeomtryHelper;
import com.enjoyor.soa.traffic.util.helper.ReflectHelper;
import com.enjoyor.soa.traffic.util.helper.TimeHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;

@Service
@Transactional
@SuppressWarnings("rawtypes")
public class SchemeInfoService implements ISchemeInfoService{

	@Autowired
	private ISchemeInfoMapper iSchemeInfoMapper;
	
	@Autowired
	private IPubLogMapper iPubLogMapper;
	
	@Autowired
	private ISchemeCheckMapper iSchemeCheckMapper;
	
	@Autowired
	private ISchemeFileMapper iSchemeFileMapper;
	
	@Autowired
	private ITaskInfoMapper iTaskInfoMapper;
	
	@Autowired
	private IExecuteTaskInfoMapper iExecuteTaskInfoMapper;
	@Autowired
	private ITaskDetailInfoMapper  iTaskDetailInfoMapper;
	
	@Autowired
	private IRouteInfoMapper iRouteInfoMapper;

	@Autowired
	private IRltTaskTimeMapper iRltTaskTimeMapper;
	
	@SuppressWarnings("unchecked")
	@Override
	public Page getSchemeInfoPage(Page page, String schemeId, String schemeName, String schemeBeginDate,
			String schemeEndDate, String schemeRankId, String schemeStatusId) {
		// TODO Auto-generated method stub
		Map<String, String> mapBean = new HashMap<String, String>();
		mapBean.put("schemeId", schemeId);
		mapBean.put("schemeName", schemeName);
		mapBean.put("schemeBeginDate", schemeBeginDate);
		mapBean.put("schemeEndDate", schemeEndDate);
		mapBean.put("schemeRankId", schemeRankId);
		mapBean.put("schemeStatusId", schemeStatusId);
		page.setMapBean(mapBean);
		return iSchemeInfoMapper.getSchemeInfoPage(page);
	}

	@Override
	public List<SchemeInfo> getSchemeInfoList(String schemeId, String schemeName, String schemeBeginDate,
			String schemeEndDate, String schemeRankId, String schemeStatusId, Boolean isFull) {
		// TODO Auto-generated method stub
		Map<Object, Object> map = new HashMap<>();
		map.put("schemeId", schemeId);
		map.put("schemeName", schemeName);
		map.put("schemeBeginDate", schemeBeginDate);
		map.put("schemeEndDate", schemeEndDate);
		map.put("schemeRankId", schemeRankId);
		map.put("schemeStatusId", schemeStatusId);
		List<SchemeInfo> schemeInfoList = new ArrayList<SchemeInfo>();
		if(isFull) {
			schemeInfoList =iSchemeInfoMapper.getSchemeBaseInfoList(map);
		}else {
			schemeInfoList =iSchemeInfoMapper.getSchemeInfoList(map);
		}
		return schemeInfoList;
	}

	@Override
	public String insert(SchemeInfo schemeInfo, String personName) {
		// TODO Auto-generated method stub
		String schemeId = schemeInfo.getSchemeId();
		if(schemeId == null || "".equals(schemeId)) {
			schemeId = "S"+TimeHelper.getUniqueString();
		}else {
			//检验方案编号是否为空
			SchemeInfo schemeInfoEx = iSchemeInfoMapper.selectById(schemeId);
			if(schemeInfoEx != null) {
				return "false";
			}
		}
		schemeInfo.setSchemeId(schemeId);
		schemeInfo.setIsDelete(false);
		schemeInfo.setCreateTime(TimeHelper.dateToLongString());
		schemeInfo.setUpdateTime(TimeHelper.dateToLongString());
		schemeInfo.setCreatePerson(personName);
		schemeInfo.setSchemeStatusId(EnumDicPublic.WAITSUBMIT.getKey());
		schemeInfo.setSchemeStatusName(EnumDicPublic.WAITSUBMIT.getValue());//状态1234分别代表：待提交，待审核，审核通过，审核不通过
		iSchemeInfoMapper.insert(schemeInfo);
		List<SchemeFile> list = schemeInfo.getSchemeFileList();
		for(int i = 0;i<list.size();i++){
			SchemeFile schemeFile = list.get(i);
			schemeFile.setFileId("SF"+TimeHelper.getUniqueString());
			schemeFile.setSchemeId(schemeId);
			iSchemeFileMapper.insert(schemeFile);
		}
		iPubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_INSERT.getCode(),
                String.format("添加方案信息:{%s} 操作成功!", new Object[] { schemeInfo.getId() }),
                LogInfoDic.LOG_MODULAR_ENUM.TSMS_SCHEME_INFO_MANAGEMENT.getMessage());
		return schemeId;
	}

	@Override
	public void update(SchemeInfo schemeInfo, String personName) {
		// TODO Auto-generated method stub
		schemeInfo.setUpdateTime(TimeHelper.dateToLongString());
		iSchemeInfoMapper.updateByIdSelective(schemeInfo);
		//先删除，后保存新的附件
		String schemeId = schemeInfo.getSchemeId();
		iSchemeFileMapper.deleteBySchemeId(schemeId);
		List<SchemeFile> schemeFileList = schemeInfo.getSchemeFileList();
		for(SchemeFile schemeFile : schemeFileList){
			schemeFile.setFileId("SF"+TimeHelper.getUniqueString());
			schemeFile.setSchemeId(schemeId);
			iSchemeFileMapper.insert(schemeFile);
		}
		
		iPubLogMapper.saveNoramlLogInfo(personName,null, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
	                String.format("修改方案信息成功:{%s} 操作成功!", new Object[] { schemeInfo.getId() }),
	                LogInfoDic.LOG_MODULAR_ENUM.TSMS_SCHEME_INFO_MANAGEMENT.getMessage());
	}

	@Override
	public void delete(String schemeId, String personName) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
		map.put("schemeId", schemeId);
		List<SchemeInfo> SchemeInfoList = iSchemeInfoMapper.getSchemeBaseInfoList(map);
		SchemeInfo schemeInfo = new SchemeInfo();
		if(SchemeInfoList != null && SchemeInfoList.size() > 0) {
			schemeInfo = SchemeInfoList.get(0);
		}
		List<SchemeCheck> scheckList = schemeInfo.getSchemeCheckList();
		List<TaskInfo> taskList = schemeInfo.getTaskInfoList();
		List<SchemeFile> fileList = schemeInfo.getSchemeFileList();
		if(scheckList != null && scheckList.size() > 0) {
			for(SchemeCheck schemeCheck : scheckList){
				iSchemeCheckMapper.deleteById(schemeCheck.getCheckId());
			}
		}
		if(taskList != null && taskList.size() > 0) {
			for(TaskInfo taskInfo : taskList){
				//iTaskInfoMapper.deleteById(taskInfo.getTaskId());
				taskInfo.setTaskId(taskInfo.getTaskId());
		    	taskInfo.setIsDelete(true);
		    	taskInfo.setUpdateTime(TimeHelper.dateToLongString());
		    	iTaskInfoMapper.updateByIdSelective(taskInfo);
			}
		}
		if(fileList != null && fileList.size() > 0) {
			for(SchemeFile schemeFile : fileList){
				iSchemeFileMapper.deleteById(schemeFile.getFileId());
			}
		}
		iSchemeInfoMapper.deleteById(schemeId);
		iPubLogMapper.saveNoramlLogInfo(personName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_DELETE.getCode(),
	                String.format("删除方案信息:{%s} 操作成功!", new Object[] { schemeId }),
	                LogInfoDic.LOG_MODULAR_ENUM.TSMS_SCHEME_INFO_MANAGEMENT.getMessage());
	}

	@Override
	public Boolean commit(String schemeId, String personName) {
		// TODO Auto-generated method stub
		Boolean flag = true;
		if(schemeId != null && schemeId != "") {
			SchemeInfo schemeInfo = new SchemeInfo();
			schemeInfo.setSchemeId(schemeId);
			schemeInfo.setUpdateTime(TimeHelper.dateToLongString());
			schemeInfo.setSchemeStatusId(EnumDicPublic.WAITCHECK.getKey());
			schemeInfo.setSchemeStatusName(EnumDicPublic.WAITCHECK.getValue());
			iSchemeInfoMapper.updateByIdSelective(schemeInfo);
			iPubLogMapper.saveNoramlLogInfo(personName,null, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
	                String.format("方案提交:{%s} 操作成功!", new Object[] { schemeInfo.getId() }),
	                LogInfoDic.LOG_MODULAR_ENUM.TSMS_SCHEME_INFO_MANAGEMENT.getMessage());
		}else {
			flag = false;
		}
		return flag;
	}

	@Override
	public Boolean audit(String schemeId,String schemeStatusId, String checkIdea, String personName) {
		// TODO Auto-generated method stub
		Boolean flag = true;
		//增加任务审核接口实现；
		SchemeInfo schemeInfo = new SchemeInfo();
		SchemeCheck schemeCheck = new SchemeCheck();
		if(EnumDicPublic.CHECKPASS.getKey().equals(schemeStatusId)){
			schemeInfo.setSchemeStatusId(EnumDicPublic.CHECKPASS.getKey());
			schemeInfo.setSchemeStatusName(EnumDicPublic.CHECKPASS.getValue());
			schemeCheck.setCheckStatusId(EnumDicPublic.CHECKPASS.getKey());
			schemeCheck.setCheckStatusName(EnumDicPublic.CHECKPASS.getValue());
		}else if(EnumDicPublic.CHECKREJECT.getKey().equals(schemeStatusId)){
			schemeInfo.setSchemeStatusId(EnumDicPublic.CHECKREJECT.getKey());
			schemeInfo.setSchemeStatusName(EnumDicPublic.CHECKREJECT.getValue());
			schemeCheck.setCheckStatusId(EnumDicPublic.CHECKREJECT.getKey());
			schemeCheck.setCheckStatusName(EnumDicPublic.CHECKREJECT.getValue());
		}else {
			flag = false;
			return flag;
		}
		//更新方案信息
		schemeInfo.setSchemeId(schemeId);
		schemeInfo.setUpdateTime(TimeHelper.dateToLongString());
		iSchemeInfoMapper.updateByIdSelective(schemeInfo);
		//生成审核信息
		schemeCheck.setCheckId("SC"+TimeHelper.getUniqueString());	
		schemeCheck.setSchemeId(schemeId);
		schemeCheck.setCheckPerson(personName);
		schemeCheck.setCheckTime(TimeHelper.dateToLongString());
		schemeCheck.setCheckIdea(checkIdea);
		iSchemeCheckMapper.insert(schemeCheck);
		//保存日志
		iPubLogMapper.saveNoramlLogInfo(personName,null, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
                String.format("方案审核:{%s} 操作成功!", new Object[] { schemeInfo.getId() }),
                LogInfoDic.LOG_MODULAR_ENUM.TSMS_SCHEME_INFO_MANAGEMENT.getMessage());
		return flag;
	}
	
	@Override
	//修改执行任务执行状态；
	public Boolean editExecuteTaskStatus(String executeTaskId, String executeStatusId, String executeStatusName, 
			String personName) {
		// TODO Auto-generated method stub
		Boolean flag = true;
		if(executeTaskId != null && executeTaskId != "") {
			ExecuteTaskInfo executeTaskInfo = new ExecuteTaskInfo();
			executeTaskInfo.setExecuteTaskId(executeTaskId);
			executeTaskInfo.setExecuteStatusId(executeStatusId);
			executeTaskInfo.setExecuteStatusName(executeStatusName);
			iExecuteTaskInfoMapper.updateByIdSelective(executeTaskInfo);
			iPubLogMapper.saveNoramlLogInfo(personName,null, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
	                String.format("修改执行任务状态:{%s} 操作成功!", new Object[] { executeTaskId }),
	                LogInfoDic.LOG_MODULAR_ENUM.TSMS_TASK_INFO_MANAGEMENT.getMessage());
		}else {
			flag = false;
			return flag;
		}
		return flag;
	}
	
	@Override
	//修改待执行方案状态；
	public Boolean editSchemeWaitStatus(String executeTaskId, String isWaitExecute, String personName) {
		// TODO Auto-generated method stub
		Boolean flag = true;
		if(executeTaskId != null && executeTaskId != "") {
			Boolean isWaitExecuteB = true;
			if("1".equals(isWaitExecute)) {
				isWaitExecuteB = true;
			}else if("0".equals(isWaitExecute)) {
				isWaitExecuteB = false;
			}else {
				flag = false;
				return flag;
			}
			ExecuteTaskInfo executeTaskInfo = new ExecuteTaskInfo();
			executeTaskInfo.setExecuteTaskId(executeTaskId);
			executeTaskInfo.setIsWaitExecute(isWaitExecuteB);
			iExecuteTaskInfoMapper.updateByIdSelective(executeTaskInfo);
			
			iPubLogMapper.saveNoramlLogInfo(personName,null, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
	                String.format("修改待执行状态:{%s} 操作成功!", new Object[] { executeTaskId }),
	                LogInfoDic.LOG_MODULAR_ENUM.TSMS_TASK_INFO_MANAGEMENT.getMessage());
		}else {
			flag = false;
			return flag;
		}
		return flag;
	}

	@SuppressWarnings("unchecked")
	@Override
	//待执行方案查询；
	public List getSchemeInfoForWeek(String schemeIdSea, String schemeBeginDate, String schemeEndDate, String executeStatusId, 
			String driverPoliceId, String beforeLicensePlate) {
		// TODO Auto-generated method stub
		//创建总的集合，储存所有的方案信息；
		List resultList = new ArrayList<Map<String, Object>>();
		try {
			//查询与时间区间有交集的方案信息
			Map<String, Object> schemeMap = new HashMap<String, Object>();
			schemeMap.put("schemeId", schemeIdSea);
			schemeMap.put("includeBeginDate", schemeBeginDate);
			schemeMap.put("includeEndDate", schemeEndDate);
			schemeMap.put("schemeStatusId", EnumDicPublic.CHECKPASS.getKey());
			List<SchemeInfo> schemeList = iSchemeInfoMapper.getSchemeInfoList(schemeMap);
			//查询时间区间内的执行任务信息
			Map<String, Object> taskMap = new HashMap<String, Object>();
			taskMap.put("schemeId", schemeIdSea);
			taskMap.put("beginTime", schemeBeginDate);
			taskMap.put("endTime", schemeEndDate);
			taskMap.put("executeStatusId", executeStatusId);
			taskMap.put("driverPoliceId", driverPoliceId);
			taskMap.put("beforeLicensePlate", beforeLicensePlate);
			List<TaskDetailInfo> taskDetailList = iTaskDetailInfoMapper.selectExecuteTaskBaseInfoList(taskMap);
			//按照每天进行整合方案、执行任务数据
			Date beginDate = TimeHelper.StringToDate(schemeBeginDate, "yyyy-MM-dd");
			Date endDate = TimeHelper.StringToDate(schemeEndDate, "yyyy-MM-dd");
			int days = (int) ((endDate.getTime() - beginDate.getTime()) / (1000*3600*24));
			for(int i=0; i < days+1; i++) {
				Date tempDate = TimeHelper.addDate(beginDate, i);
				String tempDateStr = TimeHelper.dateToShortString(tempDate);
				long tempDateLong = tempDate.getTime();
				List<SchemeInfo> tempSchemeList = new ArrayList<SchemeInfo>();
				for(int s = 0; s < schemeList.size(); s++){
					String schemeId = schemeList.get(s).getSchemeId();
					String beginDateStr = schemeList.get(s).getSchemeBeginDate();
					String endDateStr = schemeList.get(s).getSchemeEndDate();
					long beginDateLong = TimeHelper.StringToDate(beginDateStr, "yyyy-MM-dd").getTime();
					long endDateLong = TimeHelper.StringToDate(endDateStr, "yyyy-MM-dd").getTime();
					if(tempDateLong >= beginDateLong && tempDateLong <= endDateLong) {
						List<TaskDetailInfo> tempTaskDetailList = new ArrayList<TaskDetailInfo>();
						for(int t = 0; t < taskDetailList.size(); t++){
							String executeDate = taskDetailList.get(t).getExecuteDate();
							long executeDateLong = TimeHelper.StringToDate(executeDate, "yyyy-MM-dd").getTime();
							if(tempDateLong == executeDateLong && null != schemeId && schemeId.equals(taskDetailList.get(t).getSchemeId())) {
								TaskDetailInfo tempTaskDetail = ReflectHelper.beanToBean(taskDetailList.get(t), TaskDetailInfo.class);
								Map<String, Object> mapRoute = new HashMap<String, Object>();
								mapRoute.put("taskId", tempTaskDetail.getTaskId());
								List<RouteInfo> routeInfoList = iRouteInfoMapper.getRouteInfoList(mapRoute);
								for(RouteInfo routeInfo : routeInfoList){
									String strGem = GeomtryHelper.getGeomToStringWithGson(routeInfo.getRouteGeo());
									routeInfo.setStrArea(strGem);
								}
								tempTaskDetail.setRouteInfoList(routeInfoList);
								tempTaskDetailList.add(tempTaskDetail);
							}
						}
						SchemeInfo tempScheme = ReflectHelper.beanToBean(schemeList.get(s), SchemeInfo.class);
						tempScheme.setTaskDetailInfoList(tempTaskDetailList);
						tempSchemeList.add(tempScheme);
					}
				}
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("executeDate", tempDateStr);
				map.put("schemeList", tempSchemeList);
				resultList.add(map);
			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return resultList;
	}
	//（预演）根据时间集合获取预演方案List；
	@Override
	public List getPreviewSchemeList(String schemeBeginDate, String schemeEndDate, boolean isDetail) {
		// TODO Auto-generated method stub
		//创建总的集合，储存所有的方案信息；
		List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
		try {
			//long start1 = new Date().getTime();
			//查询与时间区间有交集的方案信息
			Map<String, Object> schemeMap = new HashMap<String, Object>();
			schemeMap.put("includeBeginDate", schemeBeginDate);
			schemeMap.put("includeEndDate", schemeEndDate);
			schemeMap.put("schemeNotStatusId", EnumDicPublic.CHECKREJECT.getKey());
			List<SchemeInfo> schemeList = iSchemeInfoMapper.getSchemeInfoList(schemeMap);
			//long start2 = new Date().getTime();
			//System.out.println("1方案查询时间"+ (start2-start1) +"ms;");
			//查询时间区间内的执行任务信息
			Map<String, Object> taskMap = new HashMap<String, Object>();
			taskMap.put("beginTime", schemeBeginDate);
			taskMap.put("endTime", schemeEndDate);
			//taskMap.put("routeTypeId", EnumDicPublic.ROUTE_EXECUTE.getKey());
			List<TaskDetailInfo> taskDetailList = iTaskDetailInfoMapper.selectExecuteTaskBaseInfoList(taskMap);
			//long start3 = new Date().getTime();
			//System.out.println("2方案查询时间"+ (start3-start2) +"ms;");
			//按照每天进行整合方案、执行任务数据
			Date beginDate = TimeHelper.StringToDate(schemeBeginDate, "yyyy-MM-dd");
			Date endDate = TimeHelper.StringToDate(schemeEndDate, "yyyy-MM-dd");
			int days = (int) ((endDate.getTime() - beginDate.getTime()) / (1000*3600*24));
			for(int i=0; i < days+1; i++) {
				Date tempDate = TimeHelper.addDate(beginDate, i);
				String tempDateStr = TimeHelper.dateToShortString(tempDate);
				long tempDateLong = tempDate.getTime();
				List<SchemeInfo> tempSchemeList = new ArrayList<SchemeInfo>();
				for(int s = 0; s < schemeList.size(); s++){
					String schemeId = schemeList.get(s).getSchemeId();
					String beginDateStr = schemeList.get(s).getSchemeBeginDate();
					String endDateStr = schemeList.get(s).getSchemeEndDate();
					long beginDateLong = TimeHelper.StringToDate(beginDateStr, "yyyy-MM-dd").getTime();
					long endDateLong = TimeHelper.StringToDate(endDateStr, "yyyy-MM-dd").getTime();
					if(tempDateLong >= beginDateLong && tempDateLong <= endDateLong) {
						List<TaskDetailInfo> tempTaskDetailList = new ArrayList<TaskDetailInfo>();
						for(int t = 0; t < taskDetailList.size(); t++){
							String executeDate = taskDetailList.get(t).getExecuteDate();
							long executeDateLong = TimeHelper.StringToDate(executeDate, "yyyy-MM-dd").getTime();
							if(tempDateLong == executeDateLong && null != schemeId && schemeId.equals(taskDetailList.get(t).getSchemeId())) {
								TaskDetailInfo tempTaskDetail = ReflectHelper.beanToBean(taskDetailList.get(t), TaskDetailInfo.class);
								if(isDetail) {
									Map<String, Object> mapRoute = new HashMap<String, Object>();
									mapRoute.put("taskId", tempTaskDetail.getTaskId());
									mapRoute.put("routeTypeId", EnumDicPublic.ROUTE_EXECUTE.getKey());
									List<RouteInfo> routeInfoList = iRouteInfoMapper.getRouteInfoList(mapRoute);
									for(RouteInfo routeInfo : routeInfoList){
										String strGem = GeomtryHelper.getGeomToStringWithGson(routeInfo.getRouteGeo());
										routeInfo.setStrArea(strGem);
									}
									tempTaskDetail.setRouteInfoList(routeInfoList);
									
									Map<String, Object> rltTimeMap = new HashMap<String, Object>();
									rltTimeMap.put("taskId", tempTaskDetail.getTaskId());
									List<RltTaskTime> rltTimeList = iRltTaskTimeMapper.selectRltTaskTimeList(rltTimeMap);
									tempTaskDetail.setRltTimeList(rltTimeList);
								}
								
								/*List<RouteInfo> routeInfoList = ReflectHelper.listToList(tempTaskDetail.getRouteInfoList(), RouteInfo.class);
								for(RouteInfo routeInfo : routeInfoList) {
									routeInfo.setRltRouteDeviceList(ReflectHelper.listToList(routeInfo.getRltRouteDeviceList(), RltRouteDevice.class));
									routeInfo.setRltRoutePostList(ReflectHelper.listToList(routeInfo.getRltRoutePostList(), RltRoutePost.class));
									routeInfo.setRoutePointList(ReflectHelper.listToList(routeInfo.getRoutePointList(), RoutePoint.class));
									String strArea = GeomtryHelper.getGeomToStringWithGson(routeInfo.getRouteGeo());
									routeInfo.setStrArea(strArea);
									routeInfo.setRouteGeo(GeomtryHelper.getJTring2Geom(strArea));
								}
								List<RltTaskTime> rltTimeList = ReflectHelper.listToList(tempTaskDetail.getRltTimeList(), RltTaskTime.class);
								tempTaskDetail.setRltTimeList(rltTimeList);
								tempTaskDetail.setRouteInfoList(routeInfoList);*/
								tempTaskDetailList.add(tempTaskDetail);
							}
						}
						SchemeInfo tempScheme = ReflectHelper.beanToBean(schemeList.get(s), SchemeInfo.class);
						tempScheme.setTaskDetailInfoList(tempTaskDetailList);
						tempSchemeList.add(tempScheme);
					}
				}
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("executeDate", tempDateStr);
				map.put("schemeList", tempSchemeList);
				resultList.add(map);
			}
			//long start4 = new Date().getTime();
			//System.out.println("3方案查询时间"+ (start4-start3) +"ms;");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return resultList;
	}
	
	/*@Override
	//待执行方案查询；
	public List getSchemeInfoForWeek(String schemeId, String schemeBeginDate, String schemeEndDate) {
		// TODO Auto-generated method stub
		//创建总的集合，储存所有的方案信息； 
		List resultList = new ArrayList<Map<String, Object>>();
		List resultAll = new ArrayList<>();
		try {
			Date beginDate = TimeHelper.StringToDate(schemeBeginDate, "yyyy-MM-dd");
			Date endDate = TimeHelper.StringToDate(schemeEndDate, "yyyy-MM-dd");
			int days = (int) ((endDate.getTime() - beginDate.getTime()) / (1000*3600*24));
			for(int i=0; i < days+1; i++) {
				Date tempDate = TimeHelper.addDate(beginDate, i);
				String tempDateStr = TimeHelper.dateToShortString(tempDate);
				
				//查询方案信息
				Map<String, Object> mapScheme = new HashMap<String, Object>();
				mapScheme.put("schemeId", schemeId);
				mapScheme.put("includeDate", tempDateStr);
				List<SchemeInfo> schemeList = iSchemeInfoMapper.getSchemeInfoList(mapScheme);
				for(SchemeInfo schemeInfo : schemeList){
					//查询执行任务Map；
					Map<String, Object> mapTask = new HashMap<String, Object>();
					mapTask.put("schemeId", schemeInfo.getSchemeId());
					mapTask.put("executeDate", tempDateStr);
					//mapTask.put("isWaitExecute", "1");
					//获取对应编号方案、对应执行时间的执行任务；
					List<TaskDetailInfo> taskDetailList = iTaskDetailInfoMapper.selectExecuteTaskBaseInfoList(mapTask);
					//赋值线路信息routeInfoList
					for(TaskDetailInfo taskDetail : taskDetailList){
						//查询线路Map；
						Map<String, Object> mapRoute = new HashMap<String, Object>();
						mapRoute.put("taskId", taskDetail.getTaskId());
						List<RouteInfo> routeInfoList = iRouteInfoMapper.getRouteInfoList(mapRoute);
						for(RouteInfo routeInfo : routeInfoList){
							String strGem = GeomtryHelper.getGeomToStringWithGson(routeInfo.getRouteGeo());
							routeInfo.setStrArea(strGem);
						}
						taskDetail.setRouteInfoList(routeInfoList);
					}
					
					schemeInfo.setTaskDetailInfoList(taskDetailList);
				}
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("executeDate", tempDateStr);
				map.put("schemeList", schemeList);
				resultAll.add(map);
			}
			
			//由于循环导致fastJson转换出现"$ref"异常，序列化转换成字符串；
			//String resultJson = JSONArray.toJSONString(resultAll,SerializerFeature.DisableCircularReferenceDetect);
			//再讲字符串转换成List；
			//resultList = JSONArray.parseArray(resultJson);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return resultAll;
	}*/
	//（预演）根据时间集合获取预演方案List；
	/*@Override
	public List getPreviewSchemeList(String schemeBeginDate, String schemeEndDate) {
		// TODO Auto-generated method stub
		//创建总的集合，储存所有的方案信息；
		List resultList = new ArrayList<Map<String, Object>>();

		List<Map<String, Object>> resultAll = new ArrayList<Map<String, Object>>();
		try {
			Date beginDate = TimeHelper.StringToDate(schemeBeginDate, "yyyy-MM-dd");
			Date endDate = TimeHelper.StringToDate(schemeEndDate, "yyyy-MM-dd");
			int days = (int) ((endDate.getTime() - beginDate.getTime()) / (1000*3600*24));
			for(int i=0; i < days+1; i++) {
				Date tempDate = TimeHelper.addDate(beginDate, i);
				String tempDateStr = TimeHelper.dateToShortString(tempDate);
				//查询方案信息
				Map<String, Object> mapScheme = new HashMap<String, Object>();
				mapScheme.put("includeDate", tempDateStr);
				List<SchemeInfo> schemeList = iSchemeInfoMapper.getSchemeInfoList(mapScheme);

				for(SchemeInfo schemeInfo : schemeList){
					//查询执行任务Map；
					Map<String, Object> mapTask = new HashMap<String, Object>();
					mapTask.put("schemeId", schemeInfo.getSchemeId());
					mapTask.put("executeDate", tempDateStr);
					mapTask.put("routeTypeId", EnumDicPublic.ROUTE_EXECUTE.getKey());
					//获取对应编号方案、对应执行时间的执行任务；
					List<TaskDetailInfo> taskDetailList = iTaskDetailInfoMapper.selectExecuteTaskDetailInfoList(mapTask);
					schemeInfo.setTaskDetailInfoList(taskDetailList);
				}
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("executeDate", tempDateStr);
				map.put("schemeList", schemeList);
				resultAll.add(map);
			}
			//System.out.print("接口出来时间："+TimeHelper.dateToString(new Date(),"yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
			//由于循环导致fastJson转换出现"$ref"异常，序列化转换成字符串；
			//String resultJson = JSONArray.toJSONString(resultAll,SerializerFeature.DisableCircularReferenceDetect);
			//再将字符串转换成List；
			//resultList = JSONArray.parseArray(resultJson);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return resultAll;
	}*/
	
	/**
	 * 实际执行开始时间查询
	 * @param taskId 任务编号
	 * @param schemeId 方案编号
	 * @param executeTaskId 执行任务编号
	 * @param executeDate 执行日期
	 * @return
	 */
	public List<Map<String, Object>> getExecuteStatusCollect(String taskId, String schemeId, String executeTaskId, 
			String executeDate){
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
		map.put("schemeId", schemeId);
		map.put("taskId", taskId);
		map.put("executeTaskId", executeTaskId);
		map.put("executeDate", executeDate);
		List<Map<String, Object>> executeStatusList = iExecuteTaskInfoMapper.selectExecuteStatusCollect(map);
		return executeStatusList;
	}
	
	/**
	 * 执行任务数量统计 
	 * @param taskId 任务编号
	 * @param schemeId 方案编号
	 * @param executeTaskId 执行任务编号
	 * @param executeDate 执行日期
	 * @return
	 */
	public List<Map<String, Object>> getRealExecuteTime(String taskId, String schemeId, String executeTaskId, 
			String executeDate){
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
		map.put("schemeId", schemeId);
		map.put("taskId", taskId);
		map.put("executeTaskId", executeTaskId);
		map.put("executeDate", executeDate);
		List<Map<String, Object>> executeTimeList = iExecuteTaskInfoMapper.selectRealExecuteTime(map);
		return executeTimeList;
	}
}
